package net.maergaiyun.controller;


import net.maergaiyun.controller.request.AccountLoginRequest;
import net.maergaiyun.controller.request.AccountRegisterRequest;
import net.maergaiyun.enums.BizCodeEnum;
import net.maergaiyun.service.AccountService;
import net.maergaiyun.service.FileService;
import net.maergaiyun.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author maergaiyun
 * @since 2024-07-31
 */
@RestController
@RequestMapping("/api/account/v1")
public class AccountController {
    @Autowired
    private FileService fileService;

    @Autowired
    private AccountService accountService;

    @PostMapping("upload")
    public JsonData uploadUserImg(@RequestPart("file") MultipartFile file) {
        String result = fileService.uploadUserImg(file);
        return result != null ? JsonData.buildSuccess() : JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL);

    }

    @PostMapping("register")
    public JsonData register(@RequestBody AccountRegisterRequest request) {
        JsonData jsonData = accountService.register(request);
        return jsonData;
    }

    @PostMapping("login")
    public JsonData login(@RequestBody AccountLoginRequest request) {
        JsonData jsonData = accountService.login(request);
        return jsonData;
    }

    @GetMapping("detail")
    public JsonData detail() {
        JsonData jsonData = accountService.detail();
        return jsonData;
    }
}

